<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    *{
      margin: 0;
      padding: 0;
    }
    .wrapper{
      width: 840px;
      height: 420px;
      background: url(./bg01.jpg) no-repeat center / cover;
      padding: 100px 250px;
      margin: 0 auto;
      box-sizing: border-box;
    }
    div h1,h3,h5{
      margin: 20px 0px;
    }
  </style>
</head>
<body>
  <div class="wrapper">
    <strong>传智教育年会抽奖</strong>
    <h1>一等奖：<span id="one">???</span></h1>
    <h3>二等奖：<span id="two">???</span></h3>
    <h5>三等奖：<span id="three">???</span></h5>
  </div>
  <script>
    //生成随机人的函数
    function ranPerson(index,result,personArr){
      const random = Math.floor(Math.random()*personArr.length)//随机索引
      result[index] = personArr[random]//填入结果数组
      personArr.splice(random,1)//删去随机过的元素
    }
    // 声明数组
    const personArr = ['周杰伦', '刘德华', '周星驰', 'Pink老师', '张学友']
    //存储中奖内容
    const result = [] 
    // 获取三个元素 
    const one = document.querySelector('#one')
    const two = document.querySelector('#two')
    const three = document.querySelector('#three')
    // 开始随机
    for(let i = 0; i < 3; i++){
      ranPerson(i,result,personArr)
      // const random = Math.floor(Math.random()*personArr.length)//随机索引
      // result[i] = personArr[random]//填入结果数组
      // personArr.splice(random,1)//删去随机过的元素
    }
    //渲染
    one.innerHTML = result[0]
    two.innerHTML = result[1]
    three.innerHTML = result[2]
  </script>
</body>
</html>